package com.siwei.mes.entity;

import cn.dev33.satoken.stp.StpUtil;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.siwei.mes.common.validator.AddGroup;
import com.siwei.mes.common.validator.UpdateGroup;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.experimental.Accessors;

import javax.persistence.Column;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.persistence.Transient;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import java.io.Serializable;
import java.util.Date;


/**
 * 温湿度管理(TemperatureAndHumidity)实体类
 *
 * @author linzi
 * @since 2023-11-26 19:44:36
 */
@Data
@Accessors(chain = true)
@Table(name = "t_temperature_and_humidity")
@ApiModel(value = "TemperatureAndHumidity", description = "温湿度管理")
public class TemperatureAndHumidity implements Serializable {
    private static final long serialVersionUID = -40700990475798201L;
    /**
     * 主键id
     */
    @Id
    @ApiModelProperty(value = "温湿度管理主键ID", name = "id")
    private Long id;
    /**
     * 类型编码
     */
    @Column(name = "type_no")
    @ApiModelProperty(value = "类型编码", name = "typeNo")
    @NotBlank(groups = {AddGroup.class, UpdateGroup.class}, message = "类型编码为空")
    private String typeNo;
    /**
     * 类型名称
     */
    @Column(name = "type_name")
    @ApiModelProperty(value = "类型名称", name = "typeName")
    @NotBlank(groups = {AddGroup.class, UpdateGroup.class}, message = "类型名称为空")
    private String typeName;
    /**
     * 记录人名称
     */
    @Column(name = "record_name")
    @ApiModelProperty(value = "记录人名称", name = "recordName")
    @NotBlank(groups = {AddGroup.class, UpdateGroup.class}, message = "记录人名称为空")
    private String recordName;
    /**
     * 记录时间
     */
    @Column(name = "record_time")
    @ApiModelProperty(value = "记录时间", name = "recordTime")
    @NotNull(groups = {AddGroup.class, UpdateGroup.class}, message = "记录时间为空")
    @JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8")
    private Date recordTime;
    /**
     * 温度
     */
    @Column(name = "temperature")
    @ApiModelProperty(value = "温度", name = "temperature")
    @NotBlank(groups = {AddGroup.class, UpdateGroup.class}, message = "温度为空")
    private String temperature;
    /**
     * 湿度
     */
    @Column(name = "humidness")
    @ApiModelProperty(value = "湿度", name = "humidness")
    @NotBlank(groups = {AddGroup.class, UpdateGroup.class}, message = "湿度为空")
    private String humidness;
    /**
     * 创建人
     */
    @Column(name = "creater")
    @ApiModelProperty(value = "创建人", name = "creater")
    private Long creater;
    /**
     * 创建时间
     */
    @Column(name = "create_time")
    @ApiModelProperty(value = "创建时间", name = "createTime")
    private Date createTime;
    /**
     * 修改人
     */
    @Column(name = "updater")
    @ApiModelProperty(value = "修改人", name = "updater")
    private Long updater;
    /**
     * 更新时间
     */
    @Column(name = "update_time")
    @ApiModelProperty(value = "更新时间", name = "updateTime")
    private Date updateTime;
    /**
     * 是否删除  1-删除
     */
    @Column(name = "is_del")
    @ApiModelProperty(value = "是否删除  1-删除", name = "isDel")
    private Integer isDel;

    @Transient
    @ApiModelProperty(value = "创建人名称")
    private String createrName;

    @Transient
    private String startTime;

    @Transient
    private String endTime;


    public TemperatureAndHumidity init(boolean isCreate) {
        this.setUpdater(StpUtil.isLogin() ? StpUtil.getLoginIdAsLong() : null)
                .setUpdateTime(new Date());
        if (isCreate) {
            this.setCreater(StpUtil.isLogin() ? StpUtil.getLoginIdAsLong() : null)
                    .setCreateTime(new Date())
                    .setIsDel(0);
        }
        return this;
    }
}
